package com.midou.administration.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.inject.internal.cglib.core.$ProcessSwitchCallback;
import com.midou.administration.bo.ClerkSelectBo;
import com.midou.administration.bo.CouponBo;
import com.midou.administration.bo.CouponBob;
import com.midou.administration.entity.UserCoupon;
import com.midou.administration.mapper.CouponMapper;
import com.midou.administration.mapper.UserCouponMapper;
import com.midou.administration.entity.Coupon;
import com.midou.administration.service.CouponService;
import com.midou.administration.service.impl.CouponServiceImpl;
import io.micrometer.core.annotation.Counted;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author MrChen
 * @since 2021-03-24
 */
@RestController
@RequestMapping("/administration/coupon")
public class CouponController  {
    @Autowired
    private CouponServiceImpl couponService;
    @Autowired
    private UserCouponMapper userCouponMapper;
    @Autowired
    private CouponMapper couponMapper;

    @Autowired
    private CouponServiceImpl couponServiceImpl;

    @RequestMapping("/all")
    public Page all(@RequestBody CouponBob couponBob){
        Page page=couponService.Select(couponBob);
        return page;

    }
    @RequestMapping("add")
    public int queryAdd(@RequestBody CouponBo couponBo){
        int c=couponService.queryAdd(couponBo);
        Coupon coupon=couponMapper.queryName(couponBo.getCpContent());
        int b=userCouponMapper.queryId(couponBo.getBuId(),coupon.getCpId(),couponBo.getBuId());
        return c+b;
    }

    /**
     * 查询没有结束和开始的活动
     * @return 集合
     */
    @RequestMapping("/queryAllByEndTime")
    public List<Coupon> queryAllByEndTime(){
        return this.couponService.queryAll();
    }

    @RequestMapping("/findDoUseridAll")
    public List<CouponBo> findDoUseridAll(Integer id){
        System.out.println(id);
        List<CouponBo> list = couponService.findDoUseridAll(id);
        return list;
    }

    @RequestMapping("/queryDelt")
    public int queryDelt(@RequestBody Integer id){
        return couponService.queryDlet(id);
    }

    /**
     * 没有开始的活动信息
     */
    @RequestMapping("/queryWeiKaiShi")
    public List<Coupon> queryWeiKaiShi(){
        return  this.couponService.weikaishi();
    }

    /**
     * 查询已将开始但是没有结束的活动信息
     */
    @RequestMapping("/queryMeiYouJieShu")
    public List<Coupon> queryMeiYouJieShu(){
        return this.couponService.kaishi();
    }


}
